package com.example.controller;

import com.example.model.Blog;
import com.example.service.BlogService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/blog2")
public class BlogController2 {

    @Autowired
    private BlogService blogService;


    @GetMapping
    public ResponseData getBlog() {
        ResponseData responseData = new ResponseData(200, "查询成功", blogService.selectBlog());
        return responseData;
    }
    @DeleteMapping("/{id}")
    public ResponseData deleBlog(@PathVariable Integer id){
        ResponseData responseData = new ResponseData(200, "删除成功", blogService.deleteBlog(id));
        return responseData;
    }
    @PostMapping
    public ResponseData PostBlog(@RequestBody Blog blog){
        ResponseData responseData = new ResponseData(200, "新增成功", blogService.addBlog(blog));
        return responseData;
    }
    @GetMapping("/{id}")
    public ResponseData getBlogId(@PathVariable Integer id){
        ResponseData responseData = new ResponseData(200, "通过id查询成功", blogService.selectBlogByID(id));
        return responseData;
    }

    @PutMapping
    public ResponseData getBlogId(@RequestBody Blog blog){
        ResponseData responseData = new ResponseData(200, "修改成功", blogService.updateBlog(blog));
        return responseData;
    }
    @GetMapping("/title/{title}")
    public ResponseData getBlogTitle(@PathVariable String title){
        Map<String, Object> map = new HashMap<>();
        map.put("title", title);
        ResponseData responseData = new ResponseData(200, "通过Title查询成功", blogService.selectBlogByTitle(map));
        return responseData;
    }




}